const toString = Object.prototype.toString

function is(val, type) {
  return toString.call(val) === `[object ${type}]`
}

function isFunction(val) {
  return is(val, 'Function')
}

function isAsyncFunction(val) {
  return is(val, 'AsyncFunction')
}

function isObject(val) {
  return val !== null && is(val, 'Object')
}

function isDate(val) {
  return val !== null && is(val, 'Date')
}

function isNumber(val) {
  return is(val, 'Number')
}

function isString(val) {
  return is(val, 'String')
}

function isBoolean(val) {
  return is(val, 'Boolean')
}

function isPromise(val) {
  return (
    is(val, 'Promise') &&
    isObject(val) &&
    isFunction(val.then) &&
    isFunction(val.catch)
  )
}

module.exports = {
  is,
  isFunction,
  isAsyncFunction,
  isObject,
  isDate,
  isPromise,
  isNumber,
  isString,
  isBoolean,
}
